wx.loadFontFace(Object object) 您所在的位置:网站首页 微信小程序 字体大小 样式怎么调 wx.loadFontFace(Object object)

wx.loadFontFace(Object object)

2024-06-20 08:41| 来源: 网络整理| 查看: 265

# wx.loadFontFace(Object object)

基础库 2.1.0 开始支持,低版本需做兼容处理。

以 Promise 风格 调用:支持

小程序插件:支持,需要小程序基础库版本不低于 2.15.0

微信 Windows 版:支持

微信 Mac 版:支持

# 功能描述

动态加载网络字体,文件地址需为下载类型。'2.10.0'起支持全局生效,需在 app.js 中调用。

注意:

字体文件返回的 contet-type 参考 font,格式不正确时会解析失败。 字体链接必须是https(ios不支持http) 字体链接必须是同源下的,或开启了cors支持,小程序的域名是servicewechat.com 工具里提示 Faild to load font可以忽略 '2.10.0' 以前仅在调用页面生效。 # 参数 # Object object 属性 类型 默认值 必填 说明 最低版本 global boolean false 否 是否全局生效 2.10.0 family string 是 定义的字体名称 source string 是 字体资源的地址。建议格式为 TTF 和 WOFF,WOFF2 在低版本的iOS上会不兼容。 desc Object 否 可选的字体描述符 结构属性 类型 默认值 必填 说明 style string 'normal' 否 字体样式,可选值为 normal / italic / oblique weight string 'normal' 否 字体粗细,可选值为 normal / bold / 100 / 200../ 900 variant string 'normal' 否 设置小型大写字母的字体显示文本,可选值为 normal / small-caps / inherit scopes Array 否 字体作用范围,可选值为 webview / native,默认 webview,设置 native 可在 Canvas 2D 下使用 success function 否 接口调用成功的回调函数 fail function 否 接口调用失败的回调函数 complete function 否 接口调用结束的回调函数(调用成功、失败都会执行) # object.success 回调函数 # 参数 # Object res 属性 类型 说明 status string 加载字体结果# object.fail 回调函数 # 参数 # Object res 属性 类型 说明 status string 加载字体结果# object.complete 回调函数 # 参数 # Object res 属性 类型 说明 status string 加载字体结果# 示例代码

在开发者工具中预览效果

wx.loadFontFace({ family: 'Bitstream Vera Serif Bold', source: 'url("https://sungd.github.io/Pacifico.ttf")', success: console.log })


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有